<?php

namespace App\Http\Controllers\Title;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Pagination\LengthAwarePaginator;
use Ramsey\Uuid\Uuid;
use App\Model\SecondLevel;

class AddSecondTitleController extends Controller
{
    public function index(Request $request)
    {
        try{
            $input = $request->all();
            $second_levels = SecondLevel::where('name', 'like', '%'.$input['search'].'%')->orderBY('weight')->paginate($input['page_size']);
            return $this->success(200, $second_levels);
        }catch (Exception $e){
            return $this->fail(500, ['Message ' => $e->getMessage()]);
        }
    }

    public function store(Request $request)
    {
        $second_levels = SecondLevel::create($request->all());
        return $second_levels;
    }

    public function show($id)
    {
        return SecondLevel::find($id);
    }

    public function update(Request $request, $id)
    {
        $second_levels = SecondLevel::find($id)->update($request->all());
        return $this->success(200, $request->all());
    }

    public function destroy(Request $request, $id)
    {
        try{
            $second_level = SecondLevel::find($id);
            $second_level->delete();
            return 200;
        }catch (Exception $e){
            return ['Message '=> $e->getMessage()];
        }
    }
}
